package javaEEBasic.day05;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class GoodsOrder {
    private List<Goods> goodsList;
    private BigDecimal totalPrice;
    private BigDecimal totalDiscount;
    private BigDecimal totalPay;

    public GoodsOrder() {
        this.goodsList = new ArrayList<>();
    }
    public void addGoods(Goods goods) {
        this.goodsList.add(goods);
    }
    public void deleteGoods(String id) {
       this.goodsList.removeIf(goods -> goods.getId().equals(id));
    }
    public void calculateTotalPrice() {
        this.totalPrice = this.goodsList.stream()
                .map(Goods::getPrice)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
    }
    public void printGoodsList() {
        this.goodsList.forEach(goods -> {
            System.out.println(goods.toString());
        });
    }

    public BigDecimal getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(BigDecimal totalPrice) {
        this.totalPrice = totalPrice;
    }

    public BigDecimal getTotalDiscount() {
        return totalDiscount;
    }

    public void setTotalDiscount(BigDecimal totalDiscount) {
        this.totalDiscount = totalDiscount;
    }

    public BigDecimal getTotalPay() {
        return totalPay;
    }

    public void setTotalPay(BigDecimal totalPay) {
        this.totalPay = totalPay;
    }
}
